package cn.jishiyu11.xeqb.http.http.i.httpbase

import android.os.Handler
import android.os.Looper

import org.json.JSONException
import org.json.JSONObject

import java.io.File
import java.io.FileOutputStream
import java.io.IOException
import java.io.InputStream
import java.util.HashMap
import java.util.concurrent.TimeUnit

import cn.jishiyu11.xeqb.http.http.i.DataCallBack
import okhttp3.Call
import okhttp3.Callback
import okhttp3.FormBody
import okhttp3.MediaType
import okhttp3.MultipartBody
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.RequestBody
import okhttp3.Response


/**
 * Created by 若兰 on 2016/1/23.
 * 一个懂得了编程乐趣的小白，希望自己
 * 能够在这个道路上走的很远，也希望自己学习到的
 * 知识可以帮助更多的人,分享就是学习的一种乐趣
 * QQ:1069584784
 * csdn:http://blog.csdn.net/wuyinlei
 */
class OkHttpManager
/**
 * 构造方法
 */
private constructor() {

    /**
     * okhttpclient实例
     */
    private val mClient: OkHttpClient

    /**
     * 因为我们请求数据一般都是子线程中请求，在这里我们使用了handler
     */
    private val mHandler: Handler

    init {

        mClient = OkHttpClient()

        /*
          在这里直接设置连接超时.读取超时，写入超时
         */
        mClient.newBuilder().connectTimeout((10 * 1000).toLong(), TimeUnit.SECONDS)
        mClient.newBuilder().readTimeout((10 * 1000).toLong(), TimeUnit.SECONDS)
        mClient.newBuilder().writeTimeout((10 * 1000).toLong(), TimeUnit.SECONDS)

        /*
         * 如果是用的3.0之前的版本  使用以下直接设置连接超时.读取超时，写入超时
         */

        //client.setConnectTimeout(10, TimeUnit.SECONDS);
        //client.setWriteTimeout(10, TimeUnit.SECONDS);
        //client.setReadTimeout(30, TimeUnit.SECONDS);

        /*
         * 初始化handler
         */
        mHandler = Handler(Looper.getMainLooper())
    }

    /*
     * GET方式请求的内部逻辑处理方式，同步的方式
     *
     * @param url
     * @return
     */
    private fun inner_getSync(url: String): Response? {
        val request = Request.Builder().url(url).build()
        var response: Response? = null
        try {
            //同步请求返回的是response对象
            response = mClient.newCall(request).execute()
        } catch (e: IOException) {
            e.printStackTrace()
        }

        return response
    }


    /*
     * 同步方法
     */
    private fun inner_getSyncString(url: String): String? {
        var result: String? = null
        try {
            /*
             * 把取得到的结果转为字符串，这里最好用string()
             */
            result = inner_getSync(url)!!.body().string()
        } catch (e: IOException) {
            e.printStackTrace()
        }

        return result
    }

    /*
     * 内部逻辑请求的方法
     *
     * @param url
     * @param callBack
     * @return
     */
    private fun inner_getAsync(url: String, name: String, callBack: DataCallBack) {
        val request = Request.Builder().url(url).build()
        mClient.newCall(request).enqueue(object : Callback {
            override fun onFailure(call: Call, e: IOException) {
                deliverDataFailure(request, name, e, callBack)
            }

            //            @Throws(IOException::class)
            override fun onResponse(call: Call, response: Response) {
                var result: String? = null
                try {
                    result = response.body().string()
                } catch (e: IOException) {
                    deliverDataFailure(request, name, e, callBack)
                }

                deliverDataSuccess(result, name, callBack)
            }
        })
    }


    /*
     * 分发失败的时候调用
     *
     * @param request
     * @param e
     * @param callBack
     */
    private fun deliverDataFailure(request: Request, name: String, e: IOException, callBack: DataCallBack?) {
        /*
         * 在这里使用异步处理
         */
        mHandler.post {
            callBack?.requestFailure(request, name, e)
        }
    }

    /*
     * 分发成功的时候调用
     * @param result
     * @param callBack
     */
    private fun deliverDataSuccess(result: String?, name: String, callBack: DataCallBack?) {
        /*
         * 在这里使用异步线程处理
         */
        mHandler.post {
            if (callBack != null) {
                try {
                    if (name.equals("GET_NET_IP")){
                        callBack?.requestSuccess(result!!, name)
                    }else {
                        if (getjson(result)) {
                            callBack?.requestSuccess(result!!, name)
                        } else {
                            callBack?.requestFailure(null!!, name, null!!)
                        }
                    }
                } catch (e: Exception) {
                    e.printStackTrace()
                }
            }
        }
    }

    private fun getjson(result: String?): Boolean {
        try {
            if (result.isNullOrEmpty()){
                println("OKHttpManager88888888888888888" + result!!.toString())
                val objects = JSONObject(result)
            }
            return true
        } catch (e: JSONException) {
            e.printStackTrace()
            return false
        }

    }

    private fun inner_postAsync(url: String, name: String, params: Map<String, Any>?, callBack: DataCallBack) {
        var params = params
        var requestBody: RequestBody
        if (params == null) {
            params = HashMap()
        }
        /*
         * 如果是3.0之前版本的，构建表单数据是下面的一句
         */
        //FormEncodingBuilder builder = new FormEncodingBuilder();

        /*
         * 3.0之后版本
         */
        val builder = FormBody.Builder()
        /*
         * 在这对添加的参数进行遍历，map遍历有四种方式，如果想要了解的可以网上查找
         */
        for ((key, value1) in params) {
            val value: String
            /*
             * 判断值是否是空的
             */
            if (value1 == null) {
                value = ""
            } else {
                value = value1.toString()
            }
            /*
             * 把key和value添加到formbody中
             */
            builder.add(key, value)
        }
        requestBody = builder.build()
        requestBody.toString()
        //结果返回
        val request = Request.Builder().url(url).post(requestBody).build()
        mClient.newCall(request).enqueue(object : Callback {
            override fun onFailure(call: Call, e: IOException) {
                deliverDataFailure(request, name, e, callBack)
            }

            //            @Throws(IOException::class)
            override fun onResponse(call: Call, response: Response) {
                val result = response.body().string()
                deliverDataSuccess(result, name, callBack)
            }
        })
    }

    /*
     * 下载文件的内部逻辑处理类
     *
     * @param url      下载地址
     * @param desDir   目标地址
     * @param callBack
     */
    private fun inner_downloadAsync(url: String, name: String, desDir: String, callBack: DataCallBack) {
        val request = Request.Builder().url(url).build()
        mClient.newCall(request).enqueue(object : Callback {
            override fun onFailure(call: Call, e: IOException) {
                deliverDataFailure(request, name, e, callBack)
            }

            @Throws(IOException::class)
            override fun onResponse(call: Call, response: Response) {

                /*
                 * 在这里进行文件的下载处理
                 */
                var inputStream: InputStream? = null
                var fileOutputStream: FileOutputStream? = null
                try {
                    //文件名和目标地址
                    val file = File(desDir, getFileName(url))
                    //把请求回来的response对象装换为字节流
                    inputStream = response.body().byteStream()
                    fileOutputStream = FileOutputStream(file)
                    var len: Int
                    val bytes = ByteArray(2048)
                    //循环读取数据
//                    while ((len = inputStream!!.read(bytes)) != -1) {
//                        fileOutputStream.write(bytes, 0, len)
//                    }

                    while (true) {
                        len = inputStream!!.read(bytes)
                        if (len != -1) {
                            fileOutputStream.write(bytes, 0, len)
                        } else {
                            break
                        }

                    }


                    //关闭文件输出流
                    fileOutputStream.flush()
                    //调用分发数据成功的方法
                    deliverDataSuccess(file.absolutePath, name, callBack)
                } catch (e: IOException) {
                    //如果失败，调用此方法
                    deliverDataFailure(request, name, e, callBack)
                    e.printStackTrace()
                } finally {
                    if (inputStream != null) {
                        inputStream.close()
                    }
                    if (fileOutputStream != null) {
                        fileOutputStream.close()
                    }

                }
            }

        })
    }

    /*
     * 根据文件url获取文件的路径名字
     *
     * @param url
     * @return
     */
    private fun getFileName(url: String): String {
        val separatorIndex = url.lastIndexOf("/")
        return if (separatorIndex < 0) url else url.substring(separatorIndex + 1, url.length)
    }

    private fun inner_postAsync(url: String, name: String, uid: String, is_face: String, name1: File, name2: File, callBack: DataCallBack) {
        /* 第一个要上传的file */
        val fileBody1 = RequestBody.create(MediaType.parse("application/octet-stream"), name1)

        /* 第一个要上传的file */
        val fileBody2 = RequestBody.create(MediaType.parse("application/octet-stream"), name2)

        val file1Name = "jsy.png"
        val mBody = MultipartBody.Builder(file1Name).setType(MultipartBody.FORM)
                /* 上传一个普通的String参数 , key 叫 "p" */
                .addFormDataPart("uid", uid)
                /* 底下是上传了两个文件 */
                .addFormDataPart("photo1", name1.toString(), fileBody1)
                .addFormDataPart("photo2", name2.toString(), fileBody2)
                .addFormDataPart("is_face", is_face)
                .build()
        //结果返回
        val request = Request.Builder().url(url).post(mBody).build()
        mClient.newCall(request).enqueue(object : Callback {
            override fun onFailure(call: Call, e: IOException) {
                deliverDataFailure(request, name, e, callBack)
            }

            @Throws(IOException::class)
            override fun onResponse(call: Call, response: Response) {
                val result = response.body().string()
                deliverDataSuccess(result, name, callBack)
            }
        })
    }

    private fun inner_postAsyncFaceResult(url: String, name: String, uid: String,
                                          real_name: String, card_no: String, ocr_nation: String,
                                          ocr_address: String, compare_score: String, ocr_gender: String, errorRate: String, is_check: String,
                                          issued_by: String, valid_date: String,
                                          name1: File, name2: File, name3: File, name4: File,
                                          callBack: DataCallBack) {
        /* 第一个要上传的file */
        val fileBody1 = RequestBody.create(MediaType.parse("application/octet-stream"), name1)

        /* 第二个要上传的file */
        val fileBody2 = RequestBody.create(MediaType.parse("application/octet-stream"), name2)

        /* 第三个要上传的file */
        val fileBody3 = RequestBody.create(MediaType.parse("application/octet-stream"), name3)

        /* 第四个要上传的file */
        val fileBody4 = RequestBody.create(MediaType.parse("application/octet-stream"), name4)

        val file1Name = "jsy.png"
        val mBody = MultipartBody.Builder(file1Name).setType(MultipartBody.FORM)
                /* 上传一个普通的String参数 , key 叫 "p" */
                .addFormDataPart("uid", uid)
                .addFormDataPart("real_name", real_name)
                .addFormDataPart("is_check", is_check)
                .addFormDataPart("card_no", card_no)
                .addFormDataPart("ocr_nation", ocr_nation)
                .addFormDataPart("ocr_gender", ocr_gender)
                .addFormDataPart("ocr_address", ocr_address)
                .addFormDataPart("compare_score", compare_score)
                .addFormDataPart("errorRate", errorRate)
                .addFormDataPart("issued_by", issued_by)
                .addFormDataPart("valid_date", valid_date)
                /* 底下是上传了两个文件 */
                .addFormDataPart("front_photo", name1.toString(), fileBody1)
                .addFormDataPart("back_photo", name2.toString(), fileBody2)
                .addFormDataPart("head_portrait", name3.toString(), fileBody3)
                .addFormDataPart("live_photo", name4.toString(), fileBody4)
                .build()
        //结果返回
        val request = Request.Builder().url(url).post(mBody).build()
        mClient.newCall(request).enqueue(object : Callback {
            override fun onFailure(call: Call, e: IOException) {
                deliverDataFailure(request, name, e, callBack)
            }

            @Throws(IOException::class)
            override fun onResponse(call: Call, response: Response) {
                val result = response.body().string()
                deliverDataSuccess(result, name, callBack)
            }
        })
    }


    private fun inner_postAsyncFace(url: String, name: String, api_key: String, api_secret: String, legality: String, image: File, callBack: DataCallBack) {
        /* 第一个要上传的file */
        val fileBody1 = RequestBody.create(MediaType.parse("application/octet-stream"), image)

        val file1Name = "jsy.png"
        val mBody = MultipartBody.Builder(file1Name).setType(MultipartBody.FORM)
                /* 上传一个普通的String参数 , key 叫 "p" */
                .addFormDataPart("api_key", api_key)
                /* 底下是上传了两个文件 */
                .addFormDataPart("image", image.toString(), fileBody1)
                .addFormDataPart("api_secret", api_secret)
                .addFormDataPart("legality", legality)
                .build()
        //结果返回
        val request = Request.Builder().url(url).post(mBody).build()
        mClient.newCall(request).enqueue(object : Callback {
            override fun onFailure(call: Call, e: IOException) {
                deliverDataFailure(request, name, e, callBack)
            }

            @Throws(IOException::class)
            override fun onResponse(call: Call, response: Response) {
                val result = response.body().string()
                deliverDataSuccess(result, name, callBack)
            }
        })
    }

    private fun inner_postAsync(url: String, name: String, uid: String, problem: String, mobile: String, email: String, name1: File?,
                                callBack: DataCallBack) {
        val mBody: MultipartBody
        if (name1 != null) {
            /* 第一个要上传的file */
            val fileBody1 = RequestBody.create(MediaType.parse("application/octet-stream"), name1)
            val file1Name = "jsy.png"
            mBody = MultipartBody.Builder(file1Name).setType(MultipartBody.FORM)
                    /* 上传一个普通的String参数 , key 叫 "p" */
                    .addFormDataPart("user_id", uid)
                    /* 底下是上传了两个文件 */
                    .addFormDataPart("photo", name1.toString(), fileBody1)
                    .addFormDataPart("problem", problem)
                    .addFormDataPart("mobile", mobile)
                    .addFormDataPart("email", email)
                    .build()
        } else {
            val file1Name = "jsy.png"
            mBody = MultipartBody.Builder(file1Name).setType(MultipartBody.FORM)
                    /* 上传一个普通的String参数 , key 叫 "p" */
                    .addFormDataPart("user_id", uid)
                    /* 底下是上传了两个文件 */
                    .addFormDataPart("problem", problem)
                    .addFormDataPart("mobile", mobile)
                    .addFormDataPart("email", email)
                    .build()
        }
        //结果返回
        val request = Request.Builder().url(url).post(mBody).build()
        mClient.newCall(request).enqueue(object : Callback {
            override fun onFailure(call: Call, e: IOException) {
                deliverDataFailure(request, name, e, callBack)
            }

            @Throws(IOException::class)
            override fun onResponse(call: Call, response: Response) {
                val result = response.body().string()
                deliverDataSuccess(result, name, callBack)
            }
        })
    }

    private fun inner_postAsync(url: String, name: String, uid: String, name1: File?, name2: File?, name3: File?, name4: File?,
                                callBack: DataCallBack) {
        val file1Name = "jsy.png"
        var mBody: MultipartBody? = null
        val fileBody1: RequestBody
        val fileBody2: RequestBody
        val fileBody3: RequestBody
        val fileBody4: RequestBody
        if (name1 != null && name2 != null && name3 != null && name4 != null) {
            fileBody1 = RequestBody.create(MediaType.parse("application/octet-stream"), name1)
            fileBody2 = RequestBody.create(MediaType.parse("application/octet-stream"), name2)
            fileBody3 = RequestBody.create(MediaType.parse("application/octet-stream"), name3)
            fileBody4 = RequestBody.create(MediaType.parse("application/octet-stream"), name4)
            mBody = MultipartBody.Builder(file1Name).setType(MultipartBody.FORM)
                    .addFormDataPart("uid", uid)
                    .addFormDataPart("photo1", name1.toString(), fileBody1)
                    .addFormDataPart("photo2", name2.toString(), fileBody2)
                    .addFormDataPart("photo3", name3.toString(), fileBody3)
                    .addFormDataPart("photo4", name4.toString(), fileBody4)
                    .build()

        } else if (name1 != null && name2 != null && name3 != null) {
            fileBody1 = RequestBody.create(MediaType.parse("application/octet-stream"), name1)
            fileBody2 = RequestBody.create(MediaType.parse("application/octet-stream"), name2)
            fileBody3 = RequestBody.create(MediaType.parse("application/octet-stream"), name3)
            mBody = MultipartBody.Builder(file1Name).setType(MultipartBody.FORM)
                    .addFormDataPart("uid", uid)
                    .addFormDataPart("photo1", name1.toString(), fileBody1)
                    .addFormDataPart("photo2", name2.toString(), fileBody2)
                    .addFormDataPart("photo3", name3.toString(), fileBody3)
                    .build()
        } else if (name2 != null && name3 != null && name4 != null) {
            fileBody2 = RequestBody.create(MediaType.parse("application/octet-stream"), name2)
            fileBody3 = RequestBody.create(MediaType.parse("application/octet-stream"), name3)
            fileBody4 = RequestBody.create(MediaType.parse("application/octet-stream"), name4)
            mBody = MultipartBody.Builder(file1Name).setType(MultipartBody.FORM)
                    .addFormDataPart("uid", uid)
                    .addFormDataPart("photo2", name2.toString(), fileBody2)
                    .addFormDataPart("photo3", name3.toString(), fileBody3)
                    .addFormDataPart("photo4", name4.toString(), fileBody4)
                    .build()
        } else if (name1 != null && name3 != null && name4 != null) {
            fileBody1 = RequestBody.create(MediaType.parse("application/octet-stream"), name1)
            fileBody3 = RequestBody.create(MediaType.parse("application/octet-stream"), name3)
            fileBody4 = RequestBody.create(MediaType.parse("application/octet-stream"), name4)
            mBody = MultipartBody.Builder(file1Name).setType(MultipartBody.FORM)
                    .addFormDataPart("uid", uid)
                    .addFormDataPart("photo1", name1.toString(), fileBody1)
                    .addFormDataPart("photo3", name3.toString(), fileBody3)
                    .addFormDataPart("photo4", name4.toString(), fileBody4)
                    .build()
        } else if (name1 != null && name2 != null && name4 != null) {
            fileBody1 = RequestBody.create(MediaType.parse("application/octet-stream"), name1)
            fileBody2 = RequestBody.create(MediaType.parse("application/octet-stream"), name2)
            fileBody4 = RequestBody.create(MediaType.parse("application/octet-stream"), name4)
            mBody = MultipartBody.Builder(file1Name).setType(MultipartBody.FORM)
                    .addFormDataPart("uid", uid)
                    .addFormDataPart("photo1", name1.toString(), fileBody1)
                    .addFormDataPart("photo2", name2.toString(), fileBody2)
                    .addFormDataPart("photo4", name4.toString(), fileBody4)
                    .build()
        } else if (name1 != null && name2 != null) {
            fileBody1 = RequestBody.create(MediaType.parse("application/octet-stream"), name1)
            fileBody2 = RequestBody.create(MediaType.parse("application/octet-stream"), name2)
            mBody = MultipartBody.Builder(file1Name).setType(MultipartBody.FORM)
                    .addFormDataPart("uid", uid)
                    .addFormDataPart("photo1", name1.toString(), fileBody1)
                    .addFormDataPart("photo2", name2.toString(), fileBody2)
                    .build()
        } else if (name1 != null && name3 != null) {
            fileBody1 = RequestBody.create(MediaType.parse("application/octet-stream"), name1)
            fileBody3 = RequestBody.create(MediaType.parse("application/octet-stream"), name3)
            mBody = MultipartBody.Builder(file1Name).setType(MultipartBody.FORM)
                    .addFormDataPart("uid", uid)
                    .addFormDataPart("photo1", name1.toString(), fileBody1)
                    .addFormDataPart("photo3", name3.toString(), fileBody3)
                    .build()
        } else if (name1 != null && name4 != null) {
            fileBody1 = RequestBody.create(MediaType.parse("application/octet-stream"), name1)
            fileBody4 = RequestBody.create(MediaType.parse("application/octet-stream"), name4)
            mBody = MultipartBody.Builder(file1Name).setType(MultipartBody.FORM)
                    .addFormDataPart("uid", uid)
                    .addFormDataPart("photo1", name1.toString(), fileBody1)
                    .addFormDataPart("photo4", name4.toString(), fileBody4)
                    .build()
        } else if (name2 != null && name3 != null) {
            fileBody2 = RequestBody.create(MediaType.parse("application/octet-stream"), name2)
            fileBody3 = RequestBody.create(MediaType.parse("application/octet-stream"), name3)
            mBody = MultipartBody.Builder(file1Name).setType(MultipartBody.FORM)
                    .addFormDataPart("uid", uid)
                    .addFormDataPart("photo2", name2.toString(), fileBody2)
                    .addFormDataPart("photo3", name3.toString(), fileBody3)
                    .build()
        } else if (name2 != null && name4 != null) {
            fileBody2 = RequestBody.create(MediaType.parse("application/octet-stream"), name2)
            fileBody4 = RequestBody.create(MediaType.parse("application/octet-stream"), name4)
            mBody = MultipartBody.Builder(file1Name).setType(MultipartBody.FORM)
                    .addFormDataPart("uid", uid)
                    .addFormDataPart("photo2", name2.toString(), fileBody2)
                    .addFormDataPart("photo4", name4.toString(), fileBody4)
                    .build()
        } else if (name3 != null && name4 != null) {
            fileBody3 = RequestBody.create(MediaType.parse("application/octet-stream"), name3)
            fileBody4 = RequestBody.create(MediaType.parse("application/octet-stream"), name4)
            mBody = MultipartBody.Builder(file1Name).setType(MultipartBody.FORM)
                    .addFormDataPart("uid", uid)
                    .addFormDataPart("photo3", name3.toString(), fileBody3)
                    .addFormDataPart("photo4", name4.toString(), fileBody4)
                    .build()
        } else if (name1 != null) {
            fileBody1 = RequestBody.create(MediaType.parse("application/octet-stream"), name1)
            mBody = MultipartBody.Builder(file1Name).setType(MultipartBody.FORM)
                    .addFormDataPart("uid", uid)
                    .addFormDataPart("photo1", name1.toString(), fileBody1)
                    .build()
        } else if (name2 != null) {
            fileBody2 = RequestBody.create(MediaType.parse("application/octet-stream"), name2)
            mBody = MultipartBody.Builder(file1Name).setType(MultipartBody.FORM)
                    .addFormDataPart("uid", uid)
                    .addFormDataPart("photo2", name2.toString(), fileBody2)
                    .build()
        } else if (name3 != null) {
            fileBody3 = RequestBody.create(MediaType.parse("application/octet-stream"), name3)
            mBody = MultipartBody.Builder(file1Name).setType(MultipartBody.FORM)
                    .addFormDataPart("uid", uid)
                    .addFormDataPart("photo3", name3.toString(), fileBody3)
                    .build()
        } else if (name4 != null) {
            fileBody4 = RequestBody.create(MediaType.parse("application/octet-stream"), name4)
            mBody = MultipartBody.Builder(file1Name).setType(MultipartBody.FORM)
                    .addFormDataPart("uid", uid)
                    .addFormDataPart("photo4", name4.toString(), fileBody4)
                    .build()
        }
        //结果返回
        val request = Request.Builder().url(url).post(mBody).build()
        mClient.newCall(request).enqueue(object : Callback {
            override fun onFailure(call: Call, e: IOException) {
                deliverDataFailure(request, name, e, callBack)
            }

            @Throws(IOException::class)
            override fun onResponse(call: Call, response: Response) {
                val result = response.body().string()
                deliverDataSuccess(result, name, callBack)
            }
        })
    }

    companion object {

        /**
         * 静态实例
         */
        private var sOkHttpManager: OkHttpManager? = null

        /*
     * 单例模式  获取OkHttpManager实例
     *
     * @return
     */
        val instance: OkHttpManager
            get() {

                if (sOkHttpManager == null) {
                    sOkHttpManager = OkHttpManager()
                }
                return sOkHttpManager as OkHttpManager
            }

        //-------------------------同步的方式请求数据--------------------------

        /*
     * 对外提供的get方法,同步的方式
     *
     * @param url 传入的地址
     * @return
     */
        fun getSync(url: String): Response? {

            //通过获取到的实例来调用内部方法
            return sOkHttpManager!!.inner_getSync(url)
        }

        /*
     * 对外提供的同步获取String的方法
     *
     * @param url
     * @return
     */
        fun getSyncString(url: String): String? {
            return sOkHttpManager!!.inner_getSyncString(url)
        }

        //-------------------------异步的方式请求数据--------------------------
        fun getAsync(url: String, name: String, callBack: DataCallBack) {
            instance.inner_getAsync(url, name, callBack)
        }


        //-------------------------提交表单--------------------------

        fun postAsync(url: String, name: String, params: Map<String, Any>?, callBack: DataCallBack) {
            instance.inner_postAsync(url, name, params, callBack)
        }


        //-------------------------文件下载--------------------------
        fun downloadAsync(url: String, name: String, desDir: String, callBack: DataCallBack) {
            instance.inner_downloadAsync(url, name, desDir, callBack)
        }

        fun uploadAsync(url: String, name: String, uid: String, is_face: String, name1: File, name2: File, callBack: DataCallBack) {
            instance.inner_postAsync(url, name, uid, is_face, name1, name2, callBack)
        }

        fun uploadAsyncFaceResult(url: String, name: String, uid: String,
                                  real_name: String, card_no: String, ocr_nation: String,
                                  ocr_address: String, compare_score: String, ocr_gender: String, errorRate: String, is_check: String,
                                  issued_by: String, valid_date: String,
                                  name1: File, name2: File, name3: File, name4: File,
                                  callBack: DataCallBack) {
            instance.inner_postAsyncFaceResult(url, name, uid,
                    real_name, card_no, ocr_nation,
                    ocr_address, compare_score, ocr_gender, errorRate, is_check, issued_by, valid_date,
                    name1, name2, name3, name4, callBack)
        }


        fun facepostimage1(url: String, name: String, api_key: String, api_secret: String, legality: String, image: File, callBack: DataCallBack) {
            instance.inner_postAsyncFace(url, name, api_key, api_secret, legality, image, callBack)
        }

        fun feedbackAsync(url: String, name: String, uid: String, problem: String, mobile: String, email: String, name1: File,
                          callBack: DataCallBack) {
            instance.inner_postAsync(url, name, uid, problem, mobile, email, name1, callBack)
        }


        fun uploadAsync(url: String, name: String, uid: String, name1: File, name2: File, name3: File, name4: File,
                        callBack: DataCallBack) {
            instance.inner_postAsync(url, name, uid, name1, name2, name3, name4, callBack)
        }
    }

}
